/////////////////////////////////////////////////////////////////////////////
// Name:        setting.cpp
// Purpose:     
// Author:      Herry Sugiharto
// Modified by: 
// Created:     14/07/2009 23:40:02
// RCS-ID:      
// Copyright:   Copyright (c) 2000, 2008 Krida Software Division
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
#include "wx/imaglist.h"
#include "choiceChart.h"
#include "choiceCustomer.h"
////@end includes

#include "slposapp.h"
#include "setting.h"

////@begin XPM images
////@end XPM images


/*!
 * Setting type definition
 */

IMPLEMENT_DYNAMIC_CLASS( Setting, wxDialog )


/*!
 * Setting event table definition
 */

BEGIN_EVENT_TABLE( Setting, wxDialog )

////@begin Setting event table entries
    EVT_INIT_DIALOG( Setting::OnInitDialog )

    EVT_BUTTON( wxID_SAVE, Setting::OnSaveClick )

////@end Setting event table entries

END_EVENT_TABLE()


/*!
 * Setting constructors
 */

Setting::Setting()
{
    Init();
}

Setting::Setting( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create(parent, id, caption, pos, size, style);
}


/*!
 * Setting creator
 */

bool Setting::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin Setting creation
    SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY|wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
    Centre();
////@end Setting creation
    return true;
}


/*!
 * Setting destructor
 */

Setting::~Setting()
{
////@begin Setting destruction
////@end Setting destruction
}


/*!
 * Member initialisation
 */

void Setting::Init()
{
////@begin Setting member initialisation
////@end Setting member initialisation
}


/*!
 * Control creation for Setting
 */

void Setting::CreateControls()
{    
////@begin Setting content construction
    Setting* itemDialog1 = this;

    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemDialog1->SetSizer(itemBoxSizer2);

    wxNotebook* itemNotebook3 = new wxNotebook( itemDialog1, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize, wxBK_DEFAULT );

    wxPanel* itemPanel4 = new wxPanel( itemNotebook3, ID_PANEL, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
    wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
    itemPanel4->SetSizer(itemBoxSizer5);

    wxStaticBox* itemStaticBoxSizer6Static = new wxStaticBox(itemPanel4, wxID_ANY, _("Default Accounts"));
    wxStaticBoxSizer* itemStaticBoxSizer6 = new wxStaticBoxSizer(itemStaticBoxSizer6Static, wxVERTICAL);
    itemBoxSizer5->Add(itemStaticBoxSizer6, 0, wxGROW|wxALL, 5);
    wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer6->Add(itemBoxSizer7, 0, wxGROW|wxLEFT|wxRIGHT, 5);
    wxStaticText* itemStaticText8 = new wxStaticText( itemPanel4, wxID_STATIC, _("Record In"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer7->Add(itemStaticText8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString itemChoice9Strings;
    choiceChart* itemChoice9 = new choiceChart( itemPanel4, ID_CHOICE_RECORDIN, wxDefaultPosition, wxDefaultSize, itemChoice9Strings, 0 );
    itemBoxSizer7->Add(itemChoice9, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer6->Add(itemBoxSizer10, 0, wxGROW|wxLEFT|wxRIGHT, 5);
    wxStaticText* itemStaticText11 = new wxStaticText( itemPanel4, wxID_STATIC, _("Cash Payment"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer10->Add(itemStaticText11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString itemChoice12Strings;
    choiceChart* itemChoice12 = new choiceChart( itemPanel4, ID_CHOICE_PAYMENT, wxDefaultPosition, wxDefaultSize, itemChoice12Strings, 0 );
    itemBoxSizer10->Add(itemChoice12, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer6->Add(itemBoxSizer13, 0, wxGROW|wxLEFT|wxRIGHT, 5);
    wxStaticText* itemStaticText14 = new wxStaticText( itemPanel4, wxID_STATIC, _("Card Payment"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer13->Add(itemStaticText14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString itemChoice15Strings;
    choiceChart* itemChoice15 = new choiceChart( itemPanel4, ID_CHOICE_CARD, wxDefaultPosition, wxDefaultSize, itemChoice15Strings, 0 );
    itemBoxSizer13->Add(itemChoice15, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticBox* itemStaticBoxSizer16Static = new wxStaticBox(itemPanel4, wxID_ANY, _("Default Customer"));
    wxStaticBoxSizer* itemStaticBoxSizer16 = new wxStaticBoxSizer(itemStaticBoxSizer16Static, wxHORIZONTAL);
    itemBoxSizer5->Add(itemStaticBoxSizer16, 0, wxGROW|wxALL, 5);
    wxStaticText* itemStaticText17 = new wxStaticText( itemPanel4, wxID_STATIC, _("Customer"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStaticBoxSizer16->Add(itemStaticText17, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString itemChoice18Strings;
    choiceCustomer* itemChoice18 = new choiceCustomer( itemPanel4, ID_CHOICE_CUST, wxDefaultPosition, wxDefaultSize, itemChoice18Strings, 0 );
    itemStaticBoxSizer16->Add(itemChoice18, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    itemNotebook3->AddPage(itemPanel4, _("Links"));

    wxPanel* itemPanel19 = new wxPanel( itemNotebook3, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
    wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL);
    itemPanel19->SetSizer(itemBoxSizer20);

    wxBoxSizer* itemBoxSizer21 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer20->Add(itemBoxSizer21, 0, wxGROW|wxALL, 5);
    wxStaticBitmap* itemStaticBitmap22 = new wxStaticBitmap( itemPanel19, wxID_STATIC, itemDialog1->GetBitmapResource(wxT("about.ico")), wxDefaultPosition, wxSize(32, 32), 0 );
    itemBoxSizer21->Add(itemStaticBitmap22, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticText* itemStaticText23 = new wxStaticText( itemPanel19, wxID_STATIC, _("This information will be printed on every receipt print out."), wxDefaultPosition, wxSize(300, -1), 0 );
    itemStaticText23->Wrap(300);
    itemBoxSizer21->Add(itemStaticText23, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticBox* itemStaticBoxSizer24Static = new wxStaticBox(itemPanel19, wxID_ANY, _("Company Info"));
    wxStaticBoxSizer* itemStaticBoxSizer24 = new wxStaticBoxSizer(itemStaticBoxSizer24Static, wxVERTICAL);
    itemBoxSizer20->Add(itemStaticBoxSizer24, 0, wxGROW|wxALL, 5);
    wxBoxSizer* itemBoxSizer25 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer24->Add(itemBoxSizer25, 0, wxGROW|wxLEFT|wxRIGHT, 5);
    wxStaticText* itemStaticText26 = new wxStaticText( itemPanel19, wxID_STATIC, _("Company Name"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer25->Add(itemStaticText26, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxTextCtrl* itemTextCtrl27 = new wxTextCtrl( itemPanel19, ID_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    itemTextCtrl27->SetMaxLength(34);
    itemBoxSizer25->Add(itemTextCtrl27, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer28 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer24->Add(itemBoxSizer28, 0, wxGROW|wxLEFT|wxRIGHT, 5);
    wxStaticText* itemStaticText29 = new wxStaticText( itemPanel19, wxID_STATIC, _("Address"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer28->Add(itemStaticText29, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxTextCtrl* itemTextCtrl30 = new wxTextCtrl( itemPanel19, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    itemTextCtrl30->SetMaxLength(34);
    itemBoxSizer28->Add(itemTextCtrl30, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer31 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer24->Add(itemBoxSizer31, 0, wxGROW|wxLEFT|wxRIGHT, 5);
    wxStaticText* itemStaticText32 = new wxStaticText( itemPanel19, wxID_STATIC, _("Phone"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer31->Add(itemStaticText32, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxTextCtrl* itemTextCtrl33 = new wxTextCtrl( itemPanel19, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    itemTextCtrl33->SetMaxLength(34);
    itemBoxSizer31->Add(itemTextCtrl33, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticBox* itemStaticBoxSizer34Static = new wxStaticBox(itemPanel19, wxID_ANY, _("Print Footer"));
    wxStaticBoxSizer* itemStaticBoxSizer34 = new wxStaticBoxSizer(itemStaticBoxSizer34Static, wxVERTICAL);
    itemBoxSizer20->Add(itemStaticBoxSizer34, 0, wxGROW|wxALL, 5);
    wxBoxSizer* itemBoxSizer35 = new wxBoxSizer(wxVERTICAL);
    itemStaticBoxSizer34->Add(itemBoxSizer35, 0, wxGROW|wxLEFT|wxRIGHT, 5);
    wxStaticText* itemStaticText36 = new wxStaticText( itemPanel19, wxID_STATIC, _("This is the info that will be printed on the end of each receipt printed. You can use this as an announcement, recent news or whatever you want."), wxDefaultPosition, wxSize(100, -1), 0 );
    itemStaticText36->Wrap(300);
    itemBoxSizer35->Add(itemStaticText36, 0, wxGROW|wxALL, 5);

    wxTextCtrl* itemTextCtrl37 = new wxTextCtrl( itemPanel19, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    itemTextCtrl37->SetMaxLength(34);
    itemBoxSizer35->Add(itemTextCtrl37, 1, wxGROW|wxALL, 5);

    itemNotebook3->AddPage(itemPanel19, _("Company"));

    itemBoxSizer2->Add(itemNotebook3, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);

    wxStdDialogButtonSizer* itemStdDialogButtonSizer38 = new wxStdDialogButtonSizer;

    itemBoxSizer2->Add(itemStdDialogButtonSizer38, 0, wxGROW|wxALL, 5);
    wxButton* itemButton39 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStdDialogButtonSizer38->AddButton(itemButton39);

    wxButton* itemButton40 = new wxButton( itemDialog1, wxID_SAVE, _("&Save"), wxDefaultPosition, wxDefaultSize, 0 );
    itemButton40->SetDefault();
    itemStdDialogButtonSizer38->AddButton(itemButton40);

    itemStdDialogButtonSizer38->Realize();

    // Set validators
    itemTextCtrl27->SetValidator( wxTextValidator(wxFILTER_NONE, & CompanyName) );
    itemTextCtrl30->SetValidator( wxTextValidator(wxFILTER_NONE, & CompanyAddress) );
    itemTextCtrl33->SetValidator( wxTextValidator(wxFILTER_NUMERIC, & CompanyPhone) );
    itemTextCtrl37->SetValidator( wxTextValidator(wxFILTER_NONE, & PrintFooter) );
////@end Setting content construction
}


/*!
 * Should we show tooltips?
 */

bool Setting::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap Setting::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin Setting bitmap retrieval
    wxUnusedVar(name);
    if (name == _T("about.ico"))
    {
        wxIcon icon(_T("about.ico"), wxBITMAP_TYPE_ICO);
        wxBitmap bitmap;
        bitmap.CopyFromIcon(icon);
        return bitmap;
    }
    return wxNullBitmap;
////@end Setting bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon Setting::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin Setting icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end Setting icon retrieval
}


/*!
 * wxEVT_INIT_DIALOG event handler for ID_SETTING
 */

void Setting::OnInitDialog( wxInitDialogEvent& event )
{
    wxUnusedVar(event);

    choiceCustomer *cmbCustomer = (choiceCustomer*) FindWindow(ID_CHOICE_CUST);
    choiceChart *cmbRecordIn = (choiceChart*) FindWindow(ID_CHOICE_RECORDIN);
    choiceChart *cmbCashPayment = (choiceChart*) FindWindow(ID_CHOICE_PAYMENT);
    choiceChart *cmbCardPayment = (choiceChart*) FindWindow(ID_CHOICE_CARD);
    
    cmbCustomer->SetSelected(wxGetApp().DefaultCustomer);
    cmbRecordIn->SetSelected(wxGetApp().ARaccount);
    cmbCashPayment->SetSelected(wxGetApp().CashAccount);
    cmbCardPayment->SetSelected(wxGetApp().CardAccount);
    
    SetCompanyName(wxGetApp().CompanyName);
    SetCompanyAddress(wxGetApp().CompanyAddress);
    SetCompanyPhone(wxGetApp().CompanyPhone);
    SetPrintFooter(wxGetApp().PrintFooter);
    
    TransferDataToWindow();
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_SAVE
 */

void Setting::OnSaveClick( wxCommandEvent& event )
{
    wxUnusedVar(event);
    
    choiceCustomer *cmbCustomer = (choiceCustomer*) FindWindow(ID_CHOICE_CUST);
    choiceChart *cmbRecordIn = (choiceChart*) FindWindow(ID_CHOICE_RECORDIN);
    choiceChart *cmbCashPayment = (choiceChart*) FindWindow(ID_CHOICE_PAYMENT);
    choiceChart *cmbCardPayment = (choiceChart*) FindWindow(ID_CHOICE_CARD);
    
    wxGetApp().DefaultCustomer = cmbCustomer->GetSelected();
    wxGetApp().ARaccount = cmbRecordIn->GetSelected();
    wxGetApp().CashAccount = cmbCashPayment->GetSelected();
    wxGetApp().CardAccount = cmbCardPayment->GetSelected();
    
    if ( Validate() && TransferDataFromWindow() )
    {
        wxGetApp().CompanyName = GetCompanyName();
        wxGetApp().CompanyAddress = GetCompanyAddress();
        wxGetApp().CompanyPhone = GetCompanyPhone();
        wxGetApp().PrintFooter = GetPrintFooter();
    }
    
    EndModal(wxID_SAVE);
}
